<?php
/**
 * Created by PhpStorm.
 * User: l
 * Date: 2016/7/21
 * Time: 13:46
 */
namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class Cart extends ActiveRecord {

    public  function  getCarts(){

        $id = Yii::$app->user->id;
        $carts = Cart::find()->where(['user_id' => $id,'del_flag'=>'1'])->orderBy('create_time DESC')->asArray()->all();
        return $carts;

    }
    public function getOneCart($user_id,$commodity_id,$attr_opt_ids){

        $carts = Cart::find()->where(['user_id' => $user_id,'del_flag'=>'1','commodity_id' =>$commodity_id,'opt_ids_json' =>$attr_opt_ids])->asArray()->one();
        return $carts;
    }

    public function getCartCommodityIds(){
        $id = \Yii::$app->user->id;
        $commodity_ids = Cart::find()->select('commodity_id')->where(['user_id' => $id,'del_flag'=>'1',])->orderBy('create_time DESC')->asArray()->all();
        return $commodity_ids;
    }
}